package Part;
import java.awt.Graphics2D;

import model.ProgBob;

import com.golden.gamedev.object.Sprite;


public class Part extends Sprite
{
	/*
	public double x;
	public double y;
	public double vx;
	public double vy;
	public Sprite icon;
    public double life;
    public double speed;
    public ProgBob myProgBob;
    public AbstractPart next;
    
    public AbstractPart (ProgBob progBob, double x, double y, Sprite icon, double speed)
    {
        this.myProgBob = progBob;
        this.x = x;
        this.y = y;
        this.icon = icon;
        this.speed = speed;
        life = 0.99;
    }
    
    public void draw (Graphics2D context)
    {
        icon.render(context, (int)x, (int)y);
    }
    */
	
	private double mySpeed;
    private double myLife;
    private double myVX;
    private double myVY;

    public Part (double x, double y, double vx, double vy, double speed)
    {
    	super();
        setLocation(x, y);
        setSpeed(speed);
        myLife = 0.99;
        setVCoordinates(vx, vy);
        setActive(true);
    }
    
    public void setVCoordinates(double x, double y)
    {
    	myVX = x; myVY = y;
    }
    
    public double getVX()
    {
    	return myVX;
    }
    
    public double getVY()
    {
    	return myVY;
    }
    
    public double getSpeed()
    {
    	return mySpeed;
    }
    
    public void setSpeed(double speed)
    {
    	mySpeed = speed;
    }
    
    public double getLife()
    {
    	return myLife;
    }
    
    public void setLife(double life)
    {
    	myLife = life;
    }
    
    
    @Override
    public void render(Graphics2D g)
    {
    	if (myLife < 0.99)
    	    this.render(g);
    }
    
    
    @Override
    public void update(long elapsedTime)
    {
    	double time = elapsedTime/1000.0;
    	myLife -= mySpeed*time;
    	
    	if (myLife <= 0.001)
    	{
    		setActive(false);
    	}
    	else if (myLife < 0.999)
    	{
    		setLocation(getX()+time*myVX, getY()+time*myVY);
    		//setActive(false);
    	}
    	
    	super.update(elapsedTime);
    }
}
